package org.zfes.snowier.cloud.zbss.loan.base.controller;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.core.data.Record;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.cloud.zbss.loan.base.model.BaseDatadictionary;
import org.zfes.snowier.cloud.zbss.loan.base.service.IBaseDatadictionaryService;
@Controller 
@RequestMapping("/loan/baseDatadictionary")
public class BaseDatadictionaryController extends BaseController {

	
	@Autowired
	private IBaseDatadictionaryService baseDatadictionaryService;
	
	//@RequiresPermissions(value="baseDatadictionary:loadBaseDatadictionaryDataSet",desc="数据字典列表")
    @RequestMapping(value="/loadBaseDatadictionaryDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadBaseDatadictionaryDataSet(@RequestParam Map<String,Object> params){
	    DataSet dataSet=  baseDatadictionaryService.loadBaseDatadictionaryDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
	//@RequiresPermissions(value="baseDatadictionary:createBaseDatadictionary",desc="数据字典添加")
    @RequestMapping(value="/createBaseDatadictionary", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createBaseDatadictionary(BaseDatadictionary baseDatadictionary){
		baseDatadictionaryService.createBaseDatadictionary(baseDatadictionary);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="baseDatadictionary:loadBaseDatadictionary",desc="数据字典加载")
    @RequestMapping(value="/loadBaseDatadictionary", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadBaseDatadictionary(Long id){
		Optional<BaseDatadictionary> ops = baseDatadictionaryService.loadBaseDatadictionaryById(id);
		return ajaxQuery("baseDatadictionary",ops);
    }
	
	//@RequiresPermissions(value="baseDatadictionary:updateBaseDatadictionary",desc="数据字典更新")
    @RequestMapping(value="/updateBaseDatadictionary", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateBaseDatadictionary(BaseDatadictionary baseDatadictionary){
		baseDatadictionaryService.updateBaseDatadictionary(baseDatadictionary);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="baseDatadictionary:deletBaseDatadictionary",desc="数据字典删除")
    @RequestMapping(value="/deleteBaseDatadictionary", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object deleteBaseDatadictionary(Long id){
		baseDatadictionaryService.deleteBaseDatadictionary(id);
		return ajaxDoneSuccess("数据操作成功 ");
    }

    //根据code查询数据字典
	//@RequiresPermissions(value="baseDatadictionary:loadBaseDatadictionaryDataSet",desc="数据字典列表")
	@RequestMapping(value="/loadBaseDatadictionaryForCode", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object loadBaseDatadictionaryForCode(String code){
		List<Record> dataSet=  baseDatadictionaryService.loadBaseDatadictionaryForCode(code);
		return dataSet;
	}
}